package cn.wolfcode.car.business.web.controller;


import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.query.StatementItemQuery;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/statementItem")
public class StatementItemController {
    //模板前缀
    private static final String prefix = "/business/statementItem/";

    @Autowired
    private IStatementItemService statementItemService;
    @Autowired
    private IStatementService statementService;
    @RequestMapping("/itemDetail")
    public String itemDetail(Long statementId, Model model){
        Statement statement = statementService.get(statementId);
        model.addAttribute("statement",statement);
        if (Statement.STATUS_CONSUME.equals(statement.getStatus())) {
            //消费中
            return prefix + "itemEdit";
        }else {
            //已支付
            return prefix + "itemDetail";
        }
    }

    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo query(StatementItemQuery qo){
        return statementItemService.query(qo);
    }

    @RequestMapping("/saveItem")
    @ResponseBody
    public AjaxResult saveItem(@RequestBody List<StatementItem> list){
        statementItemService.saveItem(list);
        return AjaxResult.success();
    }























}
